package rabbitmq.service;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @Auther: liyanhao
 * @Description: 基于插件的延迟消息的消费者
 * @Date: 2022/5/12 14:22
 * @Version: v1.0
 */
@Slf4j
@Component
public class DelayQueueConsumer {
    //监听消息
    @RabbitListener(queues = "delayed.queue")
    public void receiveDelayedQueue(String msg,Message message, Channel channel) throws IOException {
        log.info("当前时间:{}，收到延迟队列的消息：{}", new Date().toString(), msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
